package com.booza.dao;

import java.util.Collection;
import java.util.Date;
import java.util.List;

import com.booza.model.League;
import com.booza.model.LeaguePlayers;

/**
 * The DAO level interface for league management.
 */
public interface LeagueDAO extends CommonDAO
{
	League findLeagueById(Integer id);
	
	/**
	 * Find players who has accepted a league invitation which starts at the given time.
	 * 
	 * @param endDate
	 *          - time at which the league ends
	 * @param accountId
	 *          -
	 * @return players
	 */
	Collection<LeaguePlayers> getConflictingLeagues(Date endDate, Integer accountId);

	/**
	 * Find league by league name.
	 * 
	 * @param name
	 *          -name of the league.
	 * @return Return the matching league.
	 */
	Object findLeagueByName(String name);

	/**
	 * Creates a new league.
	 * 
	 * @param league
	 */
	void createLeague(League league);

	/**
	 * Adds player to the league.
	 * 
	 * @param me
	 *          -player to be added
	 */
	void addPlayerToLeague(LeaguePlayers me);

	
	Collection<League> findDraftLeagues(Integer accountId);
	
	Collection<League> findLeaguesInvitations(Integer accountId);

	Collection<League> findPreviousLeagues(Integer accountId);

	Collection<League> findRunningLeagues(Integer accountId);

	Collection<League> findUpcomingLeagues(Integer accountId);
	
	/**
	 * Find list of players invited for the league.
	 * 
	 * @param accountId 
	 * @param leagueId
	 *          - id of the league
	 * @return list of players
	 */
	Collection<LeaguePlayers> getInvitedPlayers(Integer accountId, Integer leagueId);

	
	/**
	 * Checks if the player has been added already for the given league.
	 * 
	 * @param accountId
	 *          - player ID
	 * @param leagueId
	 *          - tournament ID
	 * @return Return player details if already added, null if not.
	 */
	LeaguePlayers findPlayersById(Integer accountId, Integer leagueId);

	boolean changeLeagueStatus(Integer accountId, Integer leagueId, int status);

	List findLeagueWinsStats(Integer leagueid, List<Integer> playersIds);

	List findLeagueLoseStats(Integer leagueid, List<Integer> playersIds);

	List findLeagueDrawnStats(Integer leagueId, List<Integer> playersIds);
	
	List<Object[]> findLeagueGames(Integer leagueId, String player);	
	
	List<League> findAllPreviousLeagues();
	
	/**
	 * Find leagues matching the criteria.
	 * 
	 * @param colName
	 *          - colname of the criteria
	 * @param colValue
	 *          - keyword
	 * @return Return matching tournaments.
	 */
	Collection<League> fetchAllByParam(String colName, Object colValue);
}
